<template>
  <el-header class="header">
    <!-- 左侧部分 -->
    <div class="left-section">
      <img src="../imagesimages/logo.jpg" alt="logo" class="logo" />
    </div>
    <!-- 中间部分 -->
    <div class="center-section">
      <div class="search-box">
        <input
          type="text"
          placeholder="搜索商品"
          v-model="searchQuery"
          @keyup.enter="searchProducts"
        />

        <button @click="searchProducts">
          <svg viewBox="0 0 24 24" width="30" height="30">
            <path
              fill="currentColor"
              d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 0 0 1.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 0 0-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 0 0 5.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"
            />
          </svg>
        </button>
        <a
          ><svg viewBox="0 0 24 24" width="25" height="25">
            <path
              fill="currentColor"
              d="M9 2L7.17 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-3.17L15 2H9zm3 15c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5z"
            />
            <circle cx="12" cy="12" r="3" />
          </svg>
        </a>
      </div>
    </div>
    <!-- 右侧部分 -->
    <div class="right-section">
      <router-link to="/carts" class="nav-button">购物车</router-link>
      <router-link to="/Account_Management" class="nav-button"
        >账号管理</router-link
      >
      <router-link to="/type" class="nav-button">商品分类</router-link>
      <router-link to="/personal-center" class="nav-button"
        >个人中心</router-link
      >
      <router-link to="/login" class="nav-button">登录</router-link>
      <router-link to="/register" class="nav-button">注册</router-link>
    </div>
  </el-header>
</template>

<script>
import { Search } from "@element-plus/icons-vue";

export default {
  name: "Header",
  components: {
    Search,
  },
  data() {
    return {
      searchQuery: "",
    };
  },
  methods: {
    handleSearch() {
      console.log("搜索:", this.searchQuery);
      // 在这里添加搜索逻辑
    },
  },
};
</script>

<style scoped>
.header {
  height: 90px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 15px;
  background-color: rgb(255, 255, 255);
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
}
.logo {
  width: 150px;
  height: auto;
  margin-right: 100px;
  margin-left: 50px;
}
.left-section,
.center-section,
.right-section {
  display: flex;
  align-items: center;
}
.center-section {
  flex-grow: 1;
  margin: 0 10px;
  display: flex;
  justify-content: center; /* 水平居中 */
  align-items: center;
}
.right-section {
  display: flex;
  align-items: center;
}
.nav-button {
  margin-left: 15px;
  color: #606266;
  font-size: 16px;
  text-decoration: none;
}
.nav-button:hover {
  color: #f4a46f;
  background-color: #f0f9eb;
}
.search-box {
  width: 70%;
  display: flex;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  border: 3px solid #d9c596;
  background-color: #f4efd2;
  position: relative;
}

.search-box input {
  flex: 1;
  height: 45px;
  padding: 10px 15px;
  border: none;
  outline: none;
  font-size: 18px;
  background-color: #f4efd2;
}

.search-box button {
  margin: 5px;
  padding: 0px 15px;
  background-color: #dbdd90;
  color: #414233;
  width: 80px;
  font-size: 16px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-box a {
  position: absolute;
  right: 100px;
  top: 20px;
  cursor: pointer;
}
</style>
